package com.llkj.qingnianguoxue.circle;

import android.content.Intent;
import android.os.Bundle;

import com.jm.chat.activity.ChatActivity;
import com.jm.chat.activity.fragment.ConversationListFragment;
import com.jm.chat.adapter.ConversationListAdapter;
import com.jm.chat.application.JGApplication;
import com.jm.chat.utils.ClickConversationListener;

import cn.jpush.im.android.api.enums.ConversationType;
import cn.jpush.im.android.api.model.Conversation;
import cn.jpush.im.android.api.model.GroupInfo;
import cn.jpush.im.android.api.model.UserInfo;

public class MyConversationFragment extends ConversationListFragment implements ClickConversationListener {

    @Override
    public void onActivityCreated(Bundle savedInstanceState) {
        super.onActivityCreated(savedInstanceState);

        mConvListController.setConversationItemListener(this);
    }

    @Override
    public void onConversationItemClick(ConversationListAdapter mListAdapter,Conversation conv) {
        //点击会话条目
        Intent intent = new Intent();
        intent.putExtra(JGApplication.CONV_TITLE, conv.getTitle());
        //群聊
        if (conv.getType() == ConversationType.group) {
            if (mListAdapter.includeAtMsg(conv)) {
                intent.putExtra("atMsgId", mListAdapter.getAtMsgId(conv));
            }

            if (mListAdapter.includeAtAllMsg(conv)) {
                intent.putExtra("atAllMsgId", mListAdapter.getatAllMsgId(conv));
            }
            long groupId = ((GroupInfo) conv.getTargetInfo()).getGroupID();
            intent.putExtra(JGApplication.GROUP_ID, groupId);
            intent.putExtra(JGApplication.DRAFT, mConvListController.getAdapter().getDraft(conv.getId()));
            intent.setClass(getActivity(), MyChatActivity.class);
            startActivity(intent);
            return;
            //单聊
        } else {
            String targetId = ((UserInfo) conv.getTargetInfo()).getUserName();
            intent.putExtra(JGApplication.TARGET_ID, targetId);
            intent.putExtra(JGApplication.TARGET_APP_KEY, conv.getTargetAppKey());
            intent.putExtra(JGApplication.DRAFT, mConvListController.getAdapter().getDraft(conv.getId()));
        }
        intent.setClass(getActivity(), MyChatActivity.class);
        startActivity(intent);
    }

}
